@import '../core/style/variables';
@import '../core/style/list-common';
@import '../core/style/layout-common';


$mat-list-side-padding: 16px;
$mat-list-avatar-size: 40px;

// Normal list variables
$mat-list-top-padding: 8px;
// height for single-line lists
$mat-list-base-height: 48px;
// height for single-line lists with avatars
$mat-list-avatar-height: 56px;
// spec requires two- and three-line lists be taller
$mat-list-two-line-height: 72px;
$mat-list-three-line-height: 88px;
$mat-list-multi-line-padding: 16px;
$mat-list-icon-size: 24px;

// Dense list variables
$mat-dense-top-padding: 4px;
$mat-dense-base-height: 40px;
$mat-dense-avatar-height: 48px;
$mat-dense-two-line-height: 60px;
$mat-dense-three-line-height: 76px;
$mat-dense-multi-line-padding: 16px;
$mat-dense-list-icon-size: 20px;

$mat-list-item-inset-divider-offset: 72px;

// This mixin provides all list-item styles, changing font size and height
// based on whether the list is in dense mode.
@mixin mat-list-item-base($base-height, $avatar-height, $two-line-height,
  $three-line-height, $multi-line-padding, $icon-size) {

  // Prevents the wrapper `mat-list-item-content` from collapsing due to it
  // being `inline` by default.
  display: block;
  height: $base-height;

  .mat-list-item-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    box-sizing: border-box;
    padding: 0 $mat-list-side-padding;
    position: relative;
    height: inherit;
  }

  .mat-list-item-content-reverse {
    display: flex;
    align-items: center;
    padding: 0 $mat-list-side-padding;
    flex-direction: row-reverse;
    justify-content: space-around;
  }

  .mat-list-item-ripple {
    @include mat-fill;

    // Disable pointer events for the ripple container because the container will overlay the
    // user content and we don't want to disable mouse events on the user content.
    // Pointer events can be safely disabled because the ripple trigger element is the host element.
    pointer-events: none;
  }

  &.mat-list-item-avatar {
    height: $avatar-height;
  }

  &.mat-2-line {
    height: $two-line-height;
  }


  &.mat-3-line {
    height: $three-line-height;
  }

  // list items with more than 3 lines should expand to match
  // the height of its contained text
  &.mat-multi-line {
    height: auto;

    .mat-list-item-content {
      padding-top: $multi-line-padding;
      padding-bottom: $multi-line-padding;
    }
  }

  .mat-list-text {
    @include mat-line-wrapper-base();
    padding: 0 $mat-list-side-padding;

    // We only want to override the padding if there isn't
    // an avatar or icon before the element. Since the ripple
    // will always be the first child in the container, we
    // check whether this element is the second child.
    &:nth-child(2) {
      padding: 0;
    }
  }

  .mat-list-avatar {
    flex-shrink: 0;
    width: $mat-list-avatar-size;
    height: $mat-list-avatar-size;
    border-radius: 50%;
  }

  .mat-list-icon {
    width: $icon-size;
    height: $icon-size;
    font-size: $icon-size;
    box-sizing: content-box;
    border-radius: 50%;
    padding: 4px;
  }

  .mat-divider {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;

    [dir='rtl'] & {
      left: auto;
      right: 0;
    }

    &.mat-divider-inset {
      left: $mat-list-item-inset-divider-offset;
      width: calc(100% - #{$mat-list-item-inset-divider-offset});
      margin: 0;

      [dir='rtl'] & {
        left: auto;
        right: $mat-list-item-inset-divider-offset;
      }
    }
  }
}

.mat-subheader {
  display: flex;
  box-sizing: border-box;
  padding: $mat-list-side-padding;
  align-items: center;

  // This needs slightly more specificity, because it
  // can be overwritten by the typography styles.
  .mat-list &,
  .mat-nav-list &,
  .mat-selection-list & {
    margin: 0;
  }
}

// This mixin adjusts the heights and padding based on whether the list is in dense mode.
@mixin mat-subheader-spacing($top-padding, $base-height) {
  height: $base-height;
  line-height: $base-height - $mat-list-side-padding * 2;

  &:first-child {
    margin-top: -$top-padding;
  }
}

.mat-list, .mat-nav-list, .mat-selection-list {
  padding-top: $mat-list-top-padding;
  display: block;

  .mat-subheader {
    @include mat-subheader-spacing($mat-list-top-padding, $mat-list-base-height);
  }

  .mat-list-item, .mat-list-option {
    @include mat-list-item-base(
      $mat-list-base-height,
      $mat-list-avatar-height,
      $mat-list-two-line-height,
      $mat-list-three-line-height,
      $mat-list-multi-line-padding,
      $mat-list-icon-size
    );
  }
}


.mat-list[dense], .mat-nav-list[dense], .mat-selection-list[dense] {

  padding-top: $mat-dense-top-padding;
  display: block;

  .mat-subheader {
    @include mat-subheader-spacing($mat-dense-top-padding, $mat-dense-base-height);
  }

  .mat-list-item, .mat-list-option {
    @include mat-list-item-base(
      $mat-dense-base-height,
      $mat-dense-avatar-height,
      $mat-dense-two-line-height,
      $mat-dense-three-line-height,
      $mat-dense-multi-line-padding,
      $mat-dense-list-icon-size
    );
  }
}


.mat-nav-list {
  a {
    text-decoration: none;
    color: inherit;
  }

  .mat-list-item-content {
    cursor: pointer;

    &:hover, &.mat-list-item-focus {
      outline: none;
    }
  }
}

.mat-list-option {
  &:not([disabled]) {
    cursor: pointer;
  }
}
